package unwdmi.dto;

import java.sql.*;
import java.util.HashMap;

/**
 * An object for storing data from measurements
 * @author Stephan E G Veenstra
 * @version 0.0.1
 */
public class MeasurementDTO {
	
	public Integer station;
	public String date;
	public String time;
	public Double temperature;
	public Double dewpoint;
	public Double airpreasureStation;
	public Double airpreasureSea;
	public Double visibility;
	public Double windSpeed;
	public Double rainfall;
	public Double snowfall;
	
	public Boolean freeze;
	public Boolean rain;
	public Boolean snow;
	public Boolean hail;
	public Boolean thunder;
	public Boolean tornado;
	
	public Double cloud;
	public Integer windDirection;
	
	public HashMap<String,Boolean> frshtt = new HashMap<String,Boolean>();
	
	/**********************
	 *** GLOBAL METHODS ***
	 *********************/
	
	public MeasurementDTO() {};
	
	public MeasurementDTO(Integer stn, String date, String time, Double temp, Double dewp, Double stp, Double slp, Double visib, Double wdsp, Double prcp, Double sndp, String frshtt, Double cldc, Integer wnddir) {
		this.setSTN(stn);
		this.setDATE(date);
		this.setTIME(time);
		this.setTEMP(temp);
		this.setDEWP(dewp);
		this.setSTP(stp);
		this.setSLP(slp);
		this.setVISIB(visib);
		this.setWDSP(wdsp);
		this.setPRCP(prcp);
		this.setSNDP(sndp);
		this.setFRSHTT(frshtt);
		this.setCLDC(cldc);
		this.setWNDDIR(wnddir);
	};
	
	@Override
	public String toString() {
		String measurement = "";
		measurement += "\n Station \t\t : " + this.station;
		measurement += "\n Date \t\t\t : " + this.date;
		measurement += "\n Time \t\t\t : " + this.time;
		measurement += "\n Temperature \t\t : " + this.temperature;
		measurement += "\n Dew-Point \t\t : " + this.dewpoint;
		measurement += "\n Air-Preasure (station)  : " + this.airpreasureStation;
		measurement += "\n Air-Preasure (sea) \t : " + this.airpreasureSea;
		measurement += "\n Visibility \t\t : " + this.visibility;
		measurement += "\n Wind-Speed \t\t : " + this.windSpeed;
		measurement += "\n Rain-Fall \t\t : " + this.rainfall;
		measurement += "\n Snow-Fall \t\t : " + this.snowfall;
		measurement += "\n Cloudy \t\t : " + this.cloud;
		measurement += "\n Wind-Direction \t : " + this.windDirection;
		return measurement;
	};
	
	public String getJSONString() {
		return "{" +
			"'stn':'"+this.station+"'," + 
			"'date':'"+this.date+"'," + 
			"'time':'"+this.time+"'," +
			"'temp':'"+this.temperature+"'," +
			"'dewp':'"+this.dewpoint+"'," +
			"'stp':'"+this.airpreasureStation+"'," +
			"'slp':'"+this.airpreasureSea+"'," +
			"'visib':'"+this.visibility+"'," +
			"'wdsp':'"+this.windSpeed+"'," +
			"'prcp':'"+this.rainfall+"'," +
			"'sndp':'"+this.snowfall+"'," +
			"'frshtt':'"+this.getFRSHTT()+"'," +
			"'cldc':'"+this.cloud+"'," +
			"'wnddir':'"+this.windDirection+"'" +
		"}";
	};
	
	/**********************
	 *** SETTER METHODS ***
	 *********************/
	
	public void setSTN(Integer stn) {
		this.station = stn;
	};
	
	public void setDATE(String date) {
		this.date = date;
	};
	
	public void setTIME(String time) {
		this.time = time;
	};
	
	public void setTEMP(Double temp) {
		this.temperature = temp;
	};
	
	public void setDEWP(Double dewp) {
		this.dewpoint = dewp;
	};
	
	public void setSTP(Double stp) {
		this.airpreasureStation = stp;
	};
	
	public void setSLP(Double slp) {
		this.airpreasureSea = slp;
	};
	
	public void setVISIB(Double visib) {
		this.visibility = visib;
	};
	
	public void setWDSP(Double wdsp) {
		this.windSpeed = wdsp;
	};
	
	public void setPRCP(Double prcp) {
		this.rainfall = prcp;
	};
	
	public void setSNDP(Double sndp) {
		this.snowfall = sndp;
	};
	
	public void setCLDC(Double cldc) {
		this.cloud = cldc;
	};
	
	public void setFRSHTT(String frshtt) {
		if(frshtt != null) {
			this.frshtt.put("freeze", frshtt.charAt(0) == '1');
			this.frshtt.put("rain", frshtt.charAt(1) == '1');
			this.frshtt.put("snow", frshtt.charAt(2) == '1');
			this.frshtt.put("hail", frshtt.charAt(3) == '1');
			this.frshtt.put("thunder", frshtt.charAt(4) == '1');
			this.frshtt.put("tornado", frshtt.charAt(5) == '1');
		};
	};
	
	public void setWNDDIR(Integer wnddir) {
		this.windDirection = wnddir;
	};
	
	/**********************
	 *** GETTER METHODS ***
	 *********************/
	
	public Integer getSTN() {
		return this.station;
	};
	
	public Date getDATE() {
		return Date.valueOf(this.date);
	};
	
	public Time getTIME() {
		return Time.valueOf(this.time);
	};
	
	public String getDATETIME() {
		return this.date + " " + this.time;
	};
	
	public Double getTEMP() {
		return this.temperature;
	};
	
	public Double getDEWP() {
		return this.dewpoint;
	};
	
	public Double getSTP() {
		return this.airpreasureStation;
	};
	
	public Double getSLP() {
		return this.airpreasureSea;
	};
	
	public Double getVISIB() {
		return this.visibility;
	};
	
	public Double getWDSP() {
		return this.windSpeed;
	};
	
	public Double getPRCP() {
		return this.rainfall;
	};
	
	public Double getSNDP() {
		return this.snowfall;
	};
	
	public String getFRSHTT() {
		if(!this.frshtt.isEmpty()) {
			return (this.frshtt.get("freeze")  ? "1" : "0") +
				   (this.frshtt.get("rain")    ? "1" : "0") +
				   (this.frshtt.get("snow")    ? "1" : "0") +
				   (this.frshtt.get("hail")    ? "1" : "0") +
				   (this.frshtt.get("thunder") ? "1" : "0") +
				   (this.frshtt.get("tornado") ? "1" : "0");
		};
		return null;
	};
	
	public Double getCLDC() {
		return this.cloud;
	};
	
	public Integer getWNDDIR() {
		return this.windDirection;
	};
	
	
}
